require(['swiper','common','rangeSelect'], function (Swiper) {
  // 第一个tab显示内容
  $(".channel-page-type").children().eq(0).show();
  // 滚动冻结
  $(".gzl-section").on("scroll", function () {
    var self = this;
    $.requestAnimationFrame(function () {
      var sTop = self.scrollTop;
      var nTop = $(".channel-page-nav").offset().top + sTop;
      if (nTop < sTop) {
        $(".nav-box").addClass("fixed");
      } else {
        $(".nav-box").removeClass("fixed");
      }
    })
  });
  // 导航
  var navItem = $(".channel-page-nav .gzl-navbar__item");
  $(".channel-page-type").css("min-height", $(window).height() - $(".nav-box").height() - $(".gzl-cell__tips").outerHeight())
  if (navItem.length > 5) {
    navItem.parent().addClass("gzl-navbar_auto");
  }
  navItem.on("click", function () {
    var section = $(".gzl-section");
    section.stop().animate({ scrollTop: $(".channel-page-nav").offset().top + section.scrollTop() }, 300)
  });
  var channelNav = new Swiper('.nav-box', {
    slidesPerView: 5,
    autoHeight: true,
    freeMode: true,
    watchSlidesVisibility: true,
    watchSlidesProgress: true
  });
  var channelNavCon = new Swiper('.channel-page-type', {
    autoHeight: true,
    spaceBetween: 12,
    thumbs: {
      swiper: channelNav
    }
  });
  // 选择城市
  $(".hotel-sel-address").on("click",function() {
    var selectPlaceTpl = _.template($("#select-place-page").html())();
    var selectPlace = $(selectPlaceTpl).appendTo(document.body);
    selectPlace.show().addClass("show");
    $(".place-index").css("height",$(window).height()/667*500);
    $(".place-index li").css("height",$(".place-index").height()/26);
    $(".place-index").show();
    // 国内海外切换
    $(".place-nav .gzl-navbar").on("click","li",function() {
      $(this).addClass("active").siblings().removeClass("active");
    })
    // 推荐城市选择
    $(".hotplace-content-info").on("click",".hotplace-list li", function() {
      $(this).addClass("on").siblings().removeClass("on");
      selectPlace.hidePopup();
      window.history.go(-1);
    })
    // 地址列表选择
    $(".place-select-content").find(".place-item").on("click",function() {
      $(".place-select-content").find(".place-item").removeClass("on");
      $(this).addClass("on");
      selectPlace.hidePopup();
      window.history.go(-1);
    })
    // 侧边首字母交互处理
    $(".place-index li").on("click",function(){
      var index = $(this).index();
      var scrollTop = $(".place-list p").eq(index).offset().top - 60;
      var nowScrollTop = $(".select-place-page .gzl-section").scrollTop();
      $(".select-place-page .gzl-section").animate({scrollTop:scrollTop + nowScrollTop},200);
    });
    // 搜索点击效果
    $(".search-bar").find("input").on("focus",function() {
      $(this).css("textAlign","left").siblings("svg").css("left",0.12 + "rem");
    })
    $(".search-bar").find("input").on("blur",function() {
      $(this).css("textAlign","center").siblings("svg").css("left",1.04 + "rem");
    })
    $.pushHistory();
  })
  // 选择星级价格
  $(".hotel-sel-level").on("click",function() {
    var selectLevelTpl = _.template($("#select-level").html())();
    $.popup({
      title: '星级/价格',
      content: selectLevelTpl,
      btn: '确定',
      btnEvent: function() {

      }
    });
    $(".level-list").on("click","li",function() {
      $(this).toggleClass("on");
    })
    //酒店价格
    $('.hotel-price-range').jRange({
      from: 0,
      to: 800,
      isRange: true,
			showLabels: true,
			showScale: false,
			step: 50,
			format: '%s',
			width: $(".select-level-box").width()-21,
			disable: false
    });
  })
  // 返回监听
  $.popstate(function () {
    var selectPlace = $(".select-place-page").length < 1;
    if (selectPlace) {
      window.history.go(-1);
    } else {
      if (!selectPlace) {
        $(".select-place-page").hidePopup();
      }
    }
  })
});